<style>
    a{color:#2e52b9;}
</style>
<div class="layui-fluid">
    <div class="layui-card">
        <form method="post" action="<?= $this->projectSet["url"]["list"] ?>">
            <input type="hidden" name="type_id" value="<?= !empty($type_id) ? $type_id : 1; ?>">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-form-item">
                    <!--
                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <select name="fee_type">
                                <option value="">费用类型</option>
                    <?php foreach ($feeType as $k => $v) { ?>
                                                            <option value="<?= $k ?>"<?= isset($fee_type) && $fee_type == $k ? " selected" : "" ?>><?= $v["name"] ?></option>
                    <?php } ?>
                            </select>
                        </div>
                    </div>
                    -->
                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <select name="pay_shouzhi_bank_id">
                                <option value="">收支账号</option>
                                <?php foreach ($shouzhiBank as $k => $v) { ?>
                                    <option value="<?= $v["id"] ?>"<?= isset($pay_shouzhi_bank_id) && $pay_shouzhi_bank_id == $v["id"] ? " selected" : "" ?>><?= $v["title"] ?></option>
                                <?php } ?>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <input type="text" name="order_no" value="<?= $order_no ?>" placeholder="订单号" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <input type="text" name="pay_time_range" id="pay_time_range" value="<?= $pay_time_range ?>" placeholder="收付日期" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <?php if ($type_id == 2) { ?>
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <select name="transport_type">
                                    <option value="">运输类型</option>
                                    <?php foreach ($transportType as $k => $v) { ?>
                                        <option value="<?= $k ?>"<?= isset($transport_type) && $transport_type == $k ? " selected" : "" ?>><?= $v["name"] ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <select name="car_id" lay-search>
                                    <option value="">车号</option>
                                    <?php foreach ($car as $k => $v) { ?>
                                        <option value="<?= $v["id"] ?>"<?= isset($car_id) && $car_id == $v["id"] ? " selected" : "" ?>><?= $v["car_number"] ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <select name="gongyingshang_custom_id" lay-search>
                                    <option value="">供应商</option>
                                    <?php foreach ($gongyingshang as $k => $v) { ?>
                                        <option value="<?= $v["id"] ?>"<?= isset($gongyingshang_custom_id) && $gongyingshang_custom_id == $v["id"] ? " selected" : "" ?>><?= $v["cmp_bf"] ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>
                    <?php } ?>
                    <div class="layui-inline">
                        <button class="layui-btn layuiadmin-btn-list customize" lay-submit lay-filter="LAY-app-contlist-search">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <div class="layui-card">
        <div class="layui-card-header">
            <span><?= $navName ?></span>
            <!--
            <span style="float:right;">
                <a href="javascript:;" onclick="return add()" class="layui-btn layui-btn-sm customize">新增订单</a>
            </span>
            -->
        </div>
        <div class="layui-card-body">
            <table class="layui-hide" id="table-data" lay-filter="table-data" style="overflow-x:scroll;"></table>

            <tool id="table-toolbar" style="display:none">
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="batchDel">
                        删除记录
                    </button>
                </div>
            </tool>

        </div>
    </div>
</div>
<script>
    var batchDelUrl = "<?= $this->projectSet["url"]["batchDel"] ?>";
    var doSelectIdsUrl = "<?= $this->projectSet["url"]["doSelectIds"] ?>";
    var so_num = "<?= $listNum ?>";
    var pageStr = "<?= $pageStr ?>";</script>
<script>
    layui.use(['laypage', 'layer', 'form', 'table', 'laydate'], function () {
    var laypage = layui.laypage
            , table = layui.table
            , frm = layui.form
            , layer = layui.layer
            , laydate = layui.laydate;
    laydate.render({
    elem: '#pay_time_range' //指定元素
            //type: 'date'
            , range: true
    });
    //var tableObj = table.render({});
    var cookiePageArray = [];
    //存储已选择数据集，用普通变量存储也行，就是一个缓存变量
    layui.data('checked', null);
    table.render({
    elem: '#table-data'
            , url: '<?= $base_url ?>'
            , toolbar: '#table-toolbar'
//            , defaultToolbar: ['filter', {
//                    title: '导出所有搜索结果' //标题
//                    , layEvent: 'export_all' //事件名，用于 toolbar 事件中使用
//                    , icon: 'layui-icon-export' //图标类名
//                }]
            , defaultToolbar: ['filter']
            , title: '<?= $navName ?>'
            , size: 'sm'
            , cellMinWidth: 100
            , height: 500
            , totalRow:true
            , cols: [[
            {type: 'checkbox', fixed: 'left', LAY_CHECKED: false}
            //, {field: 'id', title: 'ID号', width: 60, fixed: 'left'}
            , {field: 'order_no', title: '订单号', fixed: 'left', width: 140}
            , {field: 'car_number', title: '车牌号', width: 100}
            , {field: 'pay_time_tag', title: '收付日期', width: 110}
            , {field: 'order_date_tag', title: '订单日期', width: 110}
            , {field: 'title', title: '收付账户', width: 100, totalRowText: '合计:'}
<?php if ($type_id == 2) { ?>
                , {field: 'cmp_bf', title: '供应商'}
                , {field: 'transport_type_tag', title: '运输类型'}

                , {field: 'fee_type_name', title: '费用类型'}
<?php } ?>
            , {field: 'total_fee', title: '金额', width: 100, align:'right', totalRow:true}
            , {field: 'remark', title: '备注'}
<?php if ($type_id == 2) { ?>
                , {field: 'unit_fee', title: '单价', width: 100, align:'right'}
                , {field: 'num', title: '数量', width: 70, align:'right'}
                , {field: 'unit_name', title: '计费方式'}

                , {field: 'start_mileage', title: '开始公里数', width: 100, align:'right'}
                , {field: 'end_mileage', title: '结束公里数', width: 100, align:'right'}
                , {field: 'xingshi_mileage', title: '行驶公里数', width: 100, align:'right'}
                , {field: 'youhao', title: '油耗', width: 100, align:'right'}
<?php } ?>
            ]
            ]
            , done: function (res, curr, count) {
            //.假设你的表格指定的 id="sale-data"，找到框架渲染的表格
            var tbl = $('#table-data').next('.layui-table-view');
            //记下当前页数据，Ajax 请求的数据集，对应你后端返回的数据字段
            cookiePageArray = res.data;
            //记录当前也选中的chechbox个数(判断全选使用的)
            var len = 0;
            //遍历当前页数据，对比已选中项中的 id
            for (var index = 0; index < cookiePageArray.length; index++) {
            //console.log(cookiePageArray);
            if (layui.data('checked', cookiePageArray[index]['id'])) {
            //逐个判断是否选中，如果已经选中就改变选中模式
            var i = cookiePageArray[index]['LAY_TABLE_INDEX'];
            //console.log(i);
            var checkbox = $('.layui-table tr[data-index=' + i + '] input[type="checkbox"]');
            checkbox.prop('checked', true);
            checkbox.next().addClass('layui-form-checked');
            //checkbox.parent().parent().parent().addClass('layui-table-click');
            //res.data[i].LAY_CHECKED = true;
            //为了设置全选的
            len++;
            }
            }

            //console.log(this.limit + "=====" + len);
            //设置全选checkbox的选中状态，只有改变LAY_CHECKED的值， table.checkStatus才能抓取到选中的状态
            if (len === this.limit) {
            var checkboxAll = $('.layui-table-header th[data-field=0] input[type="checkbox"]');
            checkboxAll.prop('checked', true);
            checkboxAll.next().addClass('layui-form-checked');
            //checkboxAll.parent().parent().parent().addClass('layui-table-click');
            }
            //暂时只能这样渲染表单
            frm.render('checkbox');
            }
    , page: {//支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
    layout: ['count', 'prev', 'page', 'next', 'limit'] //自定义分页布局
            //,curr: 5 //设定初始在第 5 页
            , groups: 5 //只显示 1 个连续页码
            //, first: false //不显示首页
            //, last: false //不显示尾页
            , limit: <?= $pageCount ?>
    , limits: [15, 30, 50, 100, 200]
            , prev: '上一页'
            , next: '下一页'
    }
    });
    //头工具栏事件
    table.on('toolbar(table-data)', function (obj) {
    var checkStatus = table.checkStatus(obj.config.id);
    var selectData = layui.data('checked', "select_data") ? layui.data('checked').select_data : [];
    switch (obj.event) {
    
    case 'batchDel':
            var length = selectData.length;
    if (length <= 0) {
    layer.msg('请选择数据');
    return false;
    }
    batchDel();
    break;
    }
    });
    table.on('checkbox(table-data)', function (obj) {
    //console.log(obj.type); //如果触发的是全选，则为：all，如果触发的是单选，则为：one
    //全选或单选数据集不一样
    var data = 'one' === obj.type ? [obj.data] : cookiePageArray;
    var selectData = layui.data('checked', "select_data") ? layui.data('checked').select_data : [];
    //遍历数据
    $.each(data, function (index, item) {
    //假设你数据中 id 是唯一关键字
    if (obj.checked) {
    //alert(obj.tr);
    //console.log(obj.tr);
    //.增加已选中项
    layui.data('checked', {
    key: item.id, value: item
    });
    if (selectData.indexOf(item.id) > - 1) {//如果原来的键值存在,则不操作

    } else {
    selectData.push(item.id);
    }
    //obj.tr.addClass('layui-table-click');
    } else {
    //alert(0);
    //console.log(0);
    //.删除
    layui.data('checked', {
    key: item.id, remove: true
    });
    selectData.splice(selectData.indexOf(item.id), 1);
    //obj.tr.removeClass('layui-table-click');
    }
    layui.data('checked', {
    key: "select_data", value: selectData
    });
    });
    var ids = layui.data('checked', "select_data") ? layui.data('checked').select_data : [];
    $.ajax({
    type: "POST",
            dataType: "json",
            url: doSelectIdsUrl,
            data: {
            ids: ids
            },
            success: function (data) {
            }
    });
    //console.log(layui.data('checked'));
    });
    });</script>
<script src="<?= PUBLIC_URL . "/" . $this->projectSet["file"]["js"] . "/list.js?" . rand() ?>"></script>

